package cn.frank.web;

import cn.frank.domain.Colliery;
import cn.frank.domain.LineStyle;
import cn.frank.domain.Lines;
import cn.frank.domain.Points;
import cn.frank.domain.oracle.CASE_ORDER;
import cn.frank.service.mysql.ISalesDatasService;
import cn.frank.service.oracle.ICASE_ORDERService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author Frank
 * @date 10-31
 */
@RestController
@RequestMapping("/HZMD")
public class HomeController {

    @Autowired
    private ISalesDatasService salesDatasService;

    @Autowired
    private ICASE_ORDERService case_orderService;

    @RequestMapping("/hello")
    public String hello(){
        return "Hello,SpringBoot";
    }


    //@Scheduled(fixedRate = 10000)
    @GetMapping("/caseOrder")
    public List<CASE_ORDER> caseOrder(){
        System.out.println("执行后台接口");
        return case_orderService.findList();
    }



    @GetMapping("/monthSales")
    public Map<String,Object> selectTransports(String queryOption){
        System.out.println(queryOption);
        Map<String, Object> map = queryOption == null ?  Map.of("code","400","data","","msg","error"):salesDatasService.findSalesDatasList(queryOption);
        return map;
    }

    @GetMapping("/collieryPoints")
    public Map<String,Object> describeRecords(){
        Map<String,Object> map = new HashMap<>();
        map.put("code","200");
        map.put("msg","success");
        List<Colliery> collieries = new ArrayList<>();
        List<Points> points = new ArrayList<>();
        Points p1 = new Points("晋南煤业",Arrays.asList(111.31, 36.25));
        Points p2 = new Points("汾河公司",Arrays.asList(110.59,35.02));
        Points p3 = new Points("吕临煤业",Arrays.asList(111.13, 37.52));
        Points p4 = new Points("晋北煤业",Arrays.asList(112.43, 38.84));
        points.add(p1);
        points.add(p2);
        points.add(p3);
        points.add(p4);
        List<Lines> lines = new ArrayList<>();
        //坐标
        Double[] d1 = {110.59, 35.02};
        Double[] d2 = {111.13, 37.52};
        List<Double[]> coords1 = new ArrayList<>();
        coords1.add(d1);
        coords1.add(d2);
        LineStyle ls1 = new LineStyle("dashed","#93E8F8",2.5,0.5,0.3);
        Lines l1 = new Lines(coords1,ls1);
        //lines.add(l1);
        //坐标
        Double[] d3 = {111.31, 36.25};
        Double[] d4 = {112.43, 38.84};
        List<Double[]> coords2 = new ArrayList<>();
        coords2.add(d3);
        coords2.add(d4);
        LineStyle ls2 = new LineStyle("dotted","#91cc75",2.5,0.5,0.3);
        Lines l2 = new Lines(coords2,ls2);
        //lines.add(l2);

        Colliery c1 = new Colliery("山西",points,lines,true);
        collieries.add(c1);
        map.put("result",collieries);
        return map;
    }
}
